﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace ProjScan.Tools
{
	// Token: 0x02000160 RID: 352
	internal class CSVUtils
	{
		// Token: 0x06000CA2 RID: 3234 RVA: 0x00037B88 File Offset: 0x00035D88
		public static string TranslateHeader(string csvHeader)
		{
			bool flag = string.IsNullOrEmpty(csvHeader);
			string result;
			if (flag)
			{
				result = string.Empty;
			}
			else
			{
				string[] array = csvHeader.Split(new char[]
				{
					','
				});
				IEnumerable<string> values = Enumerable.Select<string, string>(array, delegate(string field)
				{
					string text;
					CSVUtils._headerMappings.TryGetValue(field.Trim(), out text);
					return (!string.IsNullOrEmpty(text)) ? text : field;
				});
				result = string.Join(",", values);
			}
			return result;
		}

		// Token: 0x06000CA3 RID: 3235 RVA: 0x00037BF0 File Offset: 0x00035DF0
		public static List<string> ParseCsvRow(string row)
		{
			List<string> list = new List<string>();
			bool flag = false;
			StringBuilder stringBuilder = new StringBuilder();
			for (int i = 0; i < row.Length; i++)
			{
				char c = row[i];
				bool flag2 = flag;
				if (flag2)
				{
					bool flag3 = c == '"' && i + 1 < row.Length && row[i + 1] == '"';
					if (flag3)
					{
						stringBuilder.Append('"');
						i++;
					}
					else
					{
						bool flag4 = c == '"';
						if (flag4)
						{
							flag = false;
							stringBuilder.Append('"');
						}
						else
						{
							stringBuilder.Append(c);
						}
					}
				}
				else
				{
					bool flag5 = c == '"';
					if (flag5)
					{
						flag = true;
						stringBuilder.Append('"');
					}
					else
					{
						bool flag6 = c == ',';
						if (flag6)
						{
							list.Add(stringBuilder.ToString());
							stringBuilder.Clear();
						}
						else
						{
							stringBuilder.Append(c);
						}
					}
				}
			}
			list.Add(stringBuilder.ToString());
			return list;
		}

		// Token: 0x06000CA4 RID: 3236 RVA: 0x00037D00 File Offset: 0x00035F00
		public static List<Dictionary<string, string>> ReadCsvFile(string filePath, string column1Name, string column2Name, string progressMessage, string progressTitle)
		{
			return CSVUtils.ReadDataFromCsvFile(filePath, column1Name, column2Name, string.Empty, string.Empty, progressMessage, progressTitle);
		}

		// Token: 0x06000CA5 RID: 3237 RVA: 0x00037D28 File Offset: 0x00035F28
		private static List<Dictionary<string, string>> ReadDataFromCsvFile(string filePath, string column1Name, string column2Name, string column3Name, string column4Name, string progressMessage, string progressTitle)
		{
			bool flag = !File.Exists(filePath);
			List<Dictionary<string, string>> result;
			if (flag)
			{
				File.Create(filePath);
				result = null;
			}
			else
			{
				List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
				using (StreamReader streamReader = new StreamReader(filePath))
				{
					int num = -1;
					int num2 = -1;
					int num3 = -1;
					int num4 = -1;
					string text = ",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)";
					Regex regex = new Regex(text);
					string text2 = streamReader.ReadLine();
					bool flag2 = text2 != null;
					if (flag2)
					{
						string[] array = regex.Split(text2);
						for (int i = 0; i < array.Length; i++)
						{
							ToolsHelper.TrimYH(array[i]);
							bool flag3 = !string.IsNullOrEmpty(column1Name) && ToolsHelper.TrimYH(array[i]) == column1Name;
							if (flag3)
							{
								num = i;
							}
							else
							{
								bool flag4 = !string.IsNullOrEmpty(column2Name) && ToolsHelper.TrimYH(array[i]) == column2Name;
								if (flag4)
								{
									num2 = i;
								}
								else
								{
									bool flag5 = !string.IsNullOrEmpty(column3Name) && ToolsHelper.TrimYH(array[i]) == column3Name;
									if (flag5)
									{
										num3 = i;
									}
									else
									{
										bool flag6 = !string.IsNullOrEmpty(column4Name) && ToolsHelper.TrimYH(array[i]) == column4Name;
										if (flag6)
										{
											num4 = i;
										}
									}
								}
							}
						}
					}
					int num5 = 0;
					ToolsHelper.ShowProgressBar(progressTitle, progressMessage, 0f, false);
					while ((text2 = streamReader.ReadLine()) != null)
					{
						Dictionary<string, string> dictionary = new Dictionary<string, string>();
						string[] array2 = regex.Split(text2);
						string value = string.Empty;
						string value2 = string.Empty;
						string value3 = string.Empty;
						string value4 = string.Empty;
						bool flag7 = num != -1;
						if (flag7)
						{
							value = ToolsHelper.TrimYH(array2[num]);
						}
						bool flag8 = num2 != -1;
						if (flag8)
						{
							value2 = ToolsHelper.TrimYH(array2[num2]);
						}
						bool flag9 = num3 != -1;
						if (flag9)
						{
							value3 = ToolsHelper.TrimYH(array2[num3]);
						}
						bool flag10 = num4 != -1;
						if (flag10)
						{
							value4 = ToolsHelper.TrimYH(array2[num4]);
						}
						bool flag11 = !string.IsNullOrEmpty(column1Name) && !string.IsNullOrEmpty(value);
						if (flag11)
						{
							dictionary.Add(column1Name, value);
						}
						bool flag12 = !string.IsNullOrEmpty(column2Name) && !string.IsNullOrEmpty(value2);
						if (flag12)
						{
							dictionary.Add(column2Name, value2);
						}
						bool flag13 = !string.IsNullOrEmpty(column3Name) && !string.IsNullOrEmpty(value3);
						if (flag13)
						{
							dictionary.Add(column3Name, value3);
						}
						bool flag14 = !string.IsNullOrEmpty(column4Name) && !string.IsNullOrEmpty(value4);
						if (flag14)
						{
							dictionary.Add(column4Name, value4);
						}
						list.Add(dictionary);
						num5++;
						ToolsHelper.ShowProgressBar(progressTitle, progressMessage, 1f / (float)num5, false);
					}
				}
				result = list;
			}
			return result;
		}

		// Token: 0x040007B7 RID: 1975
		private static readonly Dictionary<string, string> _headerMappings = new Dictionary<string, string>
		{
			{
				"Name",
				"名称"
			},
			{
				"DirID",
				"路径"
			},
			{
				"Time",
				"时间"
			},
			{
				"Quality",
				"质量"
			},
			{
				"Length",
				"长度"
			},
			{
				"Compression",
				"压缩方式"
			},
			{
				"Type",
				"类型"
			},
			{
				"ClipCount",
				"Clip数量"
			},
			{
				"AvgDensity",
				"纹素平均密度"
			},
			{
				"VarianceOfDensity",
				"纹素面密度均值方差"
			},
			{
				"Hierarch",
				"层级结构"
			},
			{
				"LODCnt",
				"LOD数量"
			},
			{
				"MissingLvl",
				"丢失等级"
			},
			{
				"ShaderName",
				"着色器名称"
			},
			{
				"Verts",
				"顶点数"
			},
			{
				"Triangle",
				"面片数"
			},
			{
				"UVRange",
				"UV范围"
			},
			{
				"VertexDensity",
				"顶点屏幕密度"
			},
			{
				"InvisibleFaces",
				"不可见面"
			},
			{
				"TexMemoryKB",
				"引用纹理内存（KB）"
			},
			{
				"TexNumber",
				"引用纹理数"
			},
			{
				"PSCompNumber",
				"粒子系统组件数"
			},
			{
				"DrawcallPeak",
				"DrawCall峰值"
			},
			{
				"OverdrawRate",
				"平均Overdraw"
			},
			{
				"ParticleNumber",
				"粒子数量"
			},
			{
				"MaxParticle",
				"最大粒子总数"
			},
			{
				"RenderMod",
				"渲染模式"
			},
			{
				"MaxTexture",
				"引用贴图最大尺寸"
			},
			{
				"MeshTriangle",
				"网格面片数"
			},
			{
				"NumberOfReferences",
				"引用数量"
			},
			{
				"NumOfReferencedAsset",
				"被引用资产数量"
			},
			{
				"TexCount",
				"纹理计数"
			},
			{
				"VN",
				"预估变体数"
			},
			{
				"SFG",
				"shader_feature(Global)数"
			},
			{
				"SFL",
				"shader_feature_local数"
			},
			{
				"MCG",
				"multi_compile(Global)数"
			},
			{
				"MCL",
				"multi_compile_local数"
			},
			{
				"BoneNum",
				"骨骼数"
			},
			{
				"Width",
				"宽度"
			},
			{
				"Height",
				"高度"
			},
			{
				"Class",
				"类名"
			}
		};
	}
}
